<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="container-fluid">
	<div class="border bg-white mb-3">
        <div class="d-flex justify-content-between thread p-3">
            <div class="btn-group" role="group">
                <?php echo $plugin_cate_html;?>
            </div>
        </div>

        <?php if ($pluginlist) { ?>
        <div class="threadlist">
        <?php foreach($pluginlist as $dir=>$plugin) { ?>

        <?php $plugin['name'] = array_value($plugin, 'name');
		    $plugin['brief'] = array_value($plugin, 'brief');
		?>

            <article class="d-flex thread" dir="<?php echo $dir; ?>">
                <div class="d-none d-md-block mx-3">
                    <a href="<?php echo url('plugin-read', array('dir'=>$dir), TRUE);?>">
                        <img src="<?php echo $plugin['icon_url']; ?>" width="54" height="54" />
                    </a>
                </div>
                <div class="col row p-0 m-0">
                    <div class="col-lg-3">
                        <p class="text-break font-weight-bold d-inline m-0">
                            <a href="<?php echo url('plugin-read', array('dir'=>$dir), TRUE);?>">
                                <?php echo $plugin['name']; ?>
                            </a>
                            <i class="icon-rmb mx-1"></i>
                            <?php echo $plugin['official']['price']; ?>
                        </p>
                        <div class="d-flex my-1">
                            <span class="small">
                                v<?php echo $plugin['version']; ?>
                            </span>
                            <?php if($plugin['have_upgrade']) { ?>
                            <span class="small text-danger font-weight-bold mx-1">
                                v<?php echo array_value($plugin, 'official_version'); ?>
                            </span>
                            <?php } ?>
                        </div>

                        <div class="d-flex justify-content-start mb-3">
                            <!-- 付费查看详情 -->
                            <?php if('official_fee' == $action && !$plugin['downloaded']) { ?>
                            <a role="button" class="btn btn-primary btn-sm buy mx-1" href="<?php echo url('plugin-read', array('dir'=>$dir), TRUE);?>"><?php echo lang('buy');?></a>
                            <?php } ?>

                            <?php if('official_free' == $action && !$plugin['downloaded']) { ?>
                            <a role="button" class="btn btn-primary btn-sm download mx-1" href="<?php echo url('plugin-download', array('dir'=>$dir,'safe_token' => $safe_token), TRUE); ?>"><?php echo lang('download');?></a>
                            <?php } ?>

                            <?php if($plugin['setting_url']) { ?>
                            <a role="button" class="btn btn-primary btn-sm setting mx-1" href="<?php echo url('plugin-setting', array('dir'=>$dir,'safe_token' => $safe_token), TRUE); ?>"><?php echo lang('setting');?></a>
                            <?php } ?>

                            <?php if(!$plugin['installed'] && $plugin['downloaded']) { ?>
                            <a role="button" class="btn btn-success btn-sm mx-1" href="<?php echo url('plugin-install', array('dir'=> $dir, 'safe_token' => $safe_token), TRUE); ?>"><?php echo lang('install');?></a>
                            <?php } ?>

                            <?php if($plugin['installed'] && $plugin['enable']) { ?>
                            <a id="disable" role="button" class="btn btn-secondary btn-sm disable mx-1" href="<?php echo url('plugin-disable', array('dir'=> $dir, 'safe_token' => $safe_token), TRUE); ?>"><?php echo lang('disable');?></a>
                            <?php } ?>

                            <?php if($plugin['installed'] && !$plugin['enable']) { ?>
                            <a id="enable" role="button" class="btn btn-secondary btn-sm enable mx-1" href="<?php echo url('plugin-enable', array('dir'=> $dir, 'safe_token' => $safe_token), TRUE); ?>"><?php echo lang('enable');?></a>
                            <?php } ?>

                            <?php if($plugin['installed']) { ?>
                            <a role="button" class="btn btn-danger btn-sm confirm mx-1" data-method="post" data-confirm-text="<?php echo lang('plugin_uninstall_confirm_tips', array('name'=>$plugin['name']));?>" href="<?php echo url('plugin-uninstall', array('dir'=> $dir, 'safe_token' => $safe_token), TRUE); ?>"><?php echo lang('uninstall');?></a>
                            <?php } ?>

                            <?php if($plugin['installed'] && $plugin['enable'] && $plugin['have_upgrade']) { ?>
                            <a role="button" class="btn btn-primary btn-sm upgrade mx-1" href="<?php echo url('plugin-upgrade', array('dir'=> $dir, 'safe_token' => $safe_token), TRUE); ?>"><?php echo lang('update');?></a>
                            <?php } ?>

                        </div>

                    </div>
                    <div class="col-lg-9 grey text-break">
                        <?php echo $plugin['brief']; ?>
                        <br>
                        <span class="small text-muted">
                            <?php echo $dir; ?>
                        </span>

                        <?php if(!empty($plugin['official']['author'])) { ?>
                        <span class="mx-3 small text-muted"><?php echo lang('author'); ?>：
                            <a href="http://www.wellcms.cn/user-<?php echo $plugin['official']['uid'];?>.html" target="_blank"><?php echo $plugin['official']['author'];?></a>
                        </span>
                        <?php } ?>
                    </div>
                </div>
            </article>
        <?php } ?>
        </div>
        <?php } else { ?>
        <article class="d-flex justify-content-center thread my-3">
            <?php echo lang('none');?>
        </article>
        <?php } ?>
	</div>

    <?php if($pagination) { ?>
    <nav>
        <ul class="pagination justify-content-center">
            <?php echo $pagination; ?>
        </ul>
    </nav>
    <?php } ?>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<script>
    var safe_token = '<?php echo $safe_token;?>';
    <?php if ('store' == $action) { ?>
        $('a.sync').on('click', function () {
            $.xpost(xn.url('plugin-store', '', true), {safe_token: safe_token}, function (code, message) {
                if (code == 0) {
                    $.alert(message).delay(1000).location();
                } else {
                    $.alert(message);
                }
            });
        });

        <?php if (FALSE === $data_verify) { ?>
            var jform = $('#form');
            jform.on('submit', function() {
                jform.reset();
                var jthis = $(this);
                var jsubmit = jthis.find('#submit');
                jsubmit.button('loading');
                var postdata = jform.serializeObject();
                $.xpost(jform.attr('action'), postdata, function(code, message) {
                    if(code == 0) {
                        jsubmit.button(message).delay(1000).location();
                    } else if(xn.is_number(code)) {
                        $.alert(message);
                        jsubmit.button('reset');
                    } else {
                        jform.find('[name="'+code+'"]').alert(message).focus();
                        jsubmit.button('reset');
                    }
                });
                return false;
            });
        <?php } ?>

    <?php } ?>

    $('#plugin').addClass('show');
    $('li.plugin, .menu-plugin').addClass('active').find('a').removeClass('collapsed');
</script>